/*
*赛区产品表格
*DivisionPdtTable.js*/

import React, { PropTypes, Component } from 'react';
import { autobind } from 'core-decorators';
import { Table,Popconfirm } from 'antd';
import { connect } from 'react-redux';

// let columns
const DivisionPdtTable =({dispatch,privateGame,data,status,competitionId,author})=>{
	// const { departmentData } = privateGame;
	// console.log(124567,data)
	data.map((item,i)=>{
		if(item.departmentName !==''&&item.description !==null){
			delete item.departmentName
		}
	})
	const columns = [
		{
			title: '备案码',
			dataIndex: 'recordCode',
			key: 'recordCode',
		},
		{
			title: '产品名称',
			dataIndex: 'productName',
			key: 'productName',
		},
		{
			title: '投资策略',
			dataIndex: 'investStrateg',
			key: 'investStrateg',
		},
		{
			title: '所属部门',
			dataIndex: 'departmentName',
			key: 'departmentName',
		},
		{
			title: '部门(自定义)',
			dataIndex: 'description',
			key: 'description',
		},
		{
			title: '状态',
			dataIndex: 'status',
			key: 'status',
			render: (item, record) => {
				if(status=='进行中' || status=='已结束'){
					return (
						<span>
							{
								item==0?"使用中":"禁用"
							}
						</span>
	        );
				}else if(author=='0'){
					return(
						<Popconfirm title={item==0?'确定禁用':'确定使用'}  cancelText="取消" okText="确定" onConfirm={() => changeStatus(item,record)}>
							{
								item==0?<a>使用中</a>:<a>禁用</a>
							}
						</Popconfirm>
					)
				}else if(author!=='0' && item == 0){
					return(
						<Popconfirm title='确定禁用' cancelText="取消" okText="确定" onConfirm={() => changeStatus(item,record)}>
							{
								item==0?<a>使用中</a>:<a>禁用</a>
							}
						</Popconfirm>
					)
				}else if(author!=='0' && item == 1){
					return(
						<span>禁用</span>
					)
				}
        
      },
		},
		{
			title: '操作',
			key: 'action',
			render: item => (
				<Popconfirm title="确定删除?"  cancelText="取消" okText="确定" onConfirm={() => onPdtDelete(item.id)}>
					{
						author=='0'?<a >删除</a>:null
					}
				</Popconfirm>
			)
		}
	];
	
	function onPdtDelete(pID){
		dispatch({
			type:'privateGame/deletEnrollePdt',
			payload:{
				competitionId:competitionId,
				id:pID,
			}
		})
	}
	function changeStatus(v,b){
		console.log(24567,v,b)
		if(v == 0){
			dispatch({
				type:'privateGame/stopEntrollProduct',
				payload:{
					 id:b.id,
					 competitionId:competitionId,
					 status:true
				}
			})
		}else{
			dispatch({
				type:'privateGame/stopEntrollProduct',
				payload:{
					 id:b.id,
					 competitionId:competitionId,
					 status:false
				}
			})
		}
	}
	return(
		<Table
			columns={columns}
			dataSource={data}
			pagination={false}
			rowKey={record =>record.id}
			size="small"
		/>
	)
} 

export default connect(({privateGame})=>({privateGame}))(DivisionPdtTable)